package timing.ukulele.auth.http;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
import timing.ukulele.auth.http.wechat.WeChatExchange;

/**
 * Http Interface注入ioc配置
 */
@Configuration
@RequiredArgsConstructor
public class ExchangeBeanConfig {

    /**
     * 注入WeChatExchange
     *
     * @return WeChatExchange
     */
    @Bean
    public WeChatExchange weChatExchange() {
        WebClient webClient = WebClient.builder().baseUrl("https://api.weixin.qq.com").build();
        HttpServiceProxyFactory httpServiceProxyFactory =
                HttpServiceProxyFactory.builderFor(WebClientAdapter.create(webClient))
                        .build();
        return httpServiceProxyFactory.createClient(WeChatExchange.class);
    }

}